package com.css.fxfzypg.modules.dpzs.repository.impl;

import com.css.fxfzypg.modules.dpzs.entity.DpzsNum;
import com.css.fxfzypg.modules.dpzs.repository.DpzsRepository;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.Timestamp;

@Repository
public class DpzsRepositoryImpl implements DpzsRepository {
    @Resource
    JdbcTemplate jdbcTemplate;
    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public void save(DpzsNum entity) {
        String sql = "INSERT INTO ypg_dpzs_num(id, num1, num2, num3, num4, num5, num6, num7, num8, del_flag, create_user, create_time) values(:id, :num1, :num2, :num3, :num4, :num5, :num6, :num7, :num8, :delFlag, :createUser, :createTime)";
        BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(entity);
        namedParameterJdbcTemplate.update(sql, source);
    }

    @Override
    public void delete(String userId, Timestamp timestamp) {
        String sql = "update ypg_dpzs_num set del_flag = '1',update_user ='" + userId + "',update_time = '" + timestamp + "' where del_flag = '0'";
        jdbcTemplate.update(sql);
    }
}
